Skip to content

Upstream C store API improvements#352

Merged
edolstra merged 2 commits intomainfrom
c-store-apis
Feb 15, 2026
Merged

Upstream C store API improvements#352
edolstra merged 2 commits intomainfrom
c-store-apis

Conversation

@edolstra
Copy link
Collaborator

@edolstra edolstra commented Feb 13, 2026

Motivation

Merge upstream PRs NixOS#14766, NixOS#14768.

Context

Summary by CodeRabbit

  • New Features

    • Added two new C API methods: one to query the full store path from a hash part, and another to copy a single store path between stores with optional repair and signature-check configuration.
  • Documentation

    • Added documentation describing the new C API methods.

(cherry picked from commit eaf474b)
(cherry picked from commit 72ab64b)
@coderabbitai
Copy link

coderabbitai bot commented Feb 13, 2026

📝 Walkthrough

Walkthrough

This pull request introduces two new C API methods to the Nix store interface: nix_store_query_path_from_hash_part() for retrieving full store paths from hash parts, and nix_store_copy_path() for copying store paths between different stores with repair and signature-check options. Documentation, header declarations, and implementations are added.

Changes

Cohort / File(s) Summary
Documentation
doc/manual/rl-next/c-api-new-store-methods.md
New documentation file describing the two new C API methods, their parameters, return values, and behavior.
API Additions
src/libstore-c/nix_api_store.h, src/libstore-c/nix_api_store.cc
Header declarations and implementations for nix_store_query_path_from_hash_part() and nix_store_copy_path(). Implementations include input validation, error handling with established patterns (NIX_CATCH_ERRS, NIX_CATCH_ERRS_NULL), and delegation to existing C++ functions.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Two new pathways through the store we trace,
One queries hashes in their rightful place,
The other copies treasures near and far,
With signatures checked beneath each star! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Upstream C store API improvements' accurately describes the main change - adding new C API methods to the store interface - and aligns well with the commit messages and code changes.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch c-store-apis

Comment @coderabbitai help to get the list of available commands and usage tips.

@edolstra edolstra changed the title C store apis Upstream C store API improvements Feb 13, 2026
Copy link
Member

@RossComputerGuy RossComputerGuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please 🙏

@github-actions
Copy link

@github-actions github-actions bot temporarily deployed to pull request February 13, 2026 18:10 Inactive
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/libstore-c/nix_api_store.cc`:
- Around line 456-470: The function nix_store_query_path_from_hash_part lacks
null checks for the store and hash params; add validation at the top (after
setting context->last_err_code = NIX_OK) to return nullptr and set
context->last_err_code = NIX_ERR_INVALID_ARG when store is null or hash is null,
mirroring the behavior in nix_store_copy_path, so you never dereference
store->ptr or use a null hash; keep the existing try/catch and
NIXC_CATCH_ERRS_NULL flow otherwise.
🧹 Nitpick comments (3)
doc/manual/rl-next/c-api-new-store-methods.md (1)

3-3: Consider including both upstream PR references.

The PR description mentions cherry-picks from both upstream PRs #14766 and #14768. The nix_store_copy_path function appears to come from #14768, so consider adding it:

-prs: [14766]
+prs: [14766, 14768]
src/libstore-c/nix_api_store.h (2)

360-369: Documentation says "empty" but function returns NULL.

The doc says "or empty if no matching path is found" but the function returns NULL (not an empty string or empty path). Consider clarifying:

 /**
  * `@brief` Query the full store path given the hash part of a valid store
- * path, or empty if no matching path is found.
+ * path.
  *
  * `@param`[out] context Optional, stores error information
  * `@param`[in] store nix store reference
  * `@param`[in] hash Hash part of path as a string
- * `@return` Store path reference, NULL if no matching path is found.
+ * `@return` Store path reference, or NULL if no matching path is found. Free with nix_store_path_free().
  */

371-382: Add @return documentation for consistency.

Other functions in this header document their return values. This function should specify what it returns:

  * `@param`[in] path The path to copy
  * `@param`[in] repair Whether to repair the path
  * `@param`[in] checkSigs Whether to check path signatures are trusted before copying
+ * `@return` NIX_OK on success, or an error code on failure.
  */

Comment on lines +456 to +470
StorePath * nix_store_query_path_from_hash_part(nix_c_context * context, Store * store, const char * hash)
{
if (context)
context->last_err_code = NIX_OK;
try {
std::optional<nix::StorePath> s = store->ptr->queryPathFromHashPart(hash);

if (!s.has_value()) {
return nullptr;
}

return new StorePath{std::move(s.value())};
}
NIXC_CATCH_ERRS_NULL
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Missing null validation for store and hash parameters.

Unlike nix_store_copy_path which validates its parameters, this function will crash if store is null (dereferencing store->ptr) or may have undefined behavior if hash is null. Consider adding validation for consistency:

🛡️ Proposed fix to add validation
 StorePath * nix_store_query_path_from_hash_part(nix_c_context * context, Store * store, const char * hash)
 {
     if (context)
         context->last_err_code = NIX_OK;
     try {
+        if (store == nullptr) {
+            nix_set_err_msg(context, NIX_ERR_UNKNOWN, "Store is null");
+            return nullptr;
+        }
+        if (hash == nullptr) {
+            nix_set_err_msg(context, NIX_ERR_UNKNOWN, "Hash is null");
+            return nullptr;
+        }
         std::optional<nix::StorePath> s = store->ptr->queryPathFromHashPart(hash);

Note: The existing nix_store_copy_closure function (line 344) also lacks null validation, so if following strict consistency with existing code, this could be considered optional.

🤖 Prompt for AI Agents
In `@src/libstore-c/nix_api_store.cc` around lines 456 - 470, The function
nix_store_query_path_from_hash_part lacks null checks for the store and hash
params; add validation at the top (after setting context->last_err_code =
NIX_OK) to return nullptr and set context->last_err_code = NIX_ERR_INVALID_ARG
when store is null or hash is null, mirroring the behavior in
nix_store_copy_path, so you never dereference store->ptr or use a null hash;
keep the existing try/catch and NIXC_CATCH_ERRS_NULL flow otherwise.

@grahamc

This comment was marked as outdated.

Copy link
Member

@cole-h cole-h left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine

@cole-h cole-h added this pull request to the merge queue Feb 13, 2026
github-merge-queue bot pushed a commit that referenced this pull request Feb 13, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 13, 2026
@edolstra edolstra added this pull request to the merge queue Feb 15, 2026
Merged via the queue into main with commit bb74be7 Feb 15, 2026
29 checks passed
@edolstra edolstra deleted the c-store-apis branch February 15, 2026 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants